package com.asa.chart;

import com.asa.hutils.MathHUtils;

/**
 * 	N维空间上的一个坐标变换
 * 
 * 
 * @author Administrator
 *
 */
public class TransformND {
	

	
	
	
	/**
	 * 平移
	 * 一般的平移思路是各个坐标加上点什么
	 * 
	 * 用乘法表示的
	 */
	public static double[][] move2(double[] xy1,double[] move) {
		
		
		double [][] asa = MathHUtils.getI(xy1.length+1);
		for (int i = 0; i < xy1.length; i++) {
			asa[i][xy1.length]=move[i];
		}
		double[][] asb = one2N(xy1);
		double[][] result = MathHUtils.chenfa(asa, asb);
		MathHUtils.print(result);

		return result;
	}


	/**
	 * 对数据进行升维
	 * @param xy1
	 * @return
	 */
	private static double[][] one2N(double[] xy1) {
		double[][] asb= new double[1][xy1.length+1];
		for (int i = 0; i < xy1.length; i++) {
			asb[0][i] = xy1[i];
		}
		asb[0][xy1.length] = 1;
		asb = MathHUtils.zhuanzhi(asb);

		return asb;
	}
	
	
	
	/**
	 * 旋转
	 * 
	 * @param args
	 */
	
	
	/**
	 * 重心
	 * 
	 * @param args
	 */
	
	
	
	
	

	
	
	
	
	
	
	
	
	public static void main(String[] args) {

//		reflection(new double[]{0,1});
		
		
//		move2(new double[] {1,1,1}, new double[] {1,1,7});
		
		
		
		
//		Perspective Transformation	透视变换矩阵
//		//这个矩阵的值数固定的
//		double[][] asa = {{1,0,0,0},
//				{0,1,0,0},
//				{0,0,-1,-1},
//				{0,0,0,0}};
//		//xyz是可变参数，指的空间中的某个点
//		double x = 1;
//		double y= 1;
//		double z= 1;
//		double[] xyz1 = {x,y,z,1};
//		double[][] up2D = MathHUtils.up2D(xyz1);
//		up2D = MathHUtils.zhuanzhi(up2D);
//		double[][] chenfa = MathHUtils.chenfa(up2D, asa);
//		
//		//刚好就得出了{x`,y`,z`,w`}
//		MathHUtils.print(chenfa);
//		
//		//计算投影点的x'x ′ 和y'y ′ 坐标,将范围映射到[-1,1]
		
		
		double[][] perspectiveTransformation = Transform3D22D.PerspectiveTransformation(20, 1, 2, -2, 2, -2);
		MathHUtils.print(perspectiveTransformation);
		double x = 1;
		double y= 1;
		double z= 1;
		double[] xyz1 = {x,y,z,1};
		double[][] up2D = MathHUtils.up2D(xyz1);
		up2D = MathHUtils.zhuanzhi(up2D);
		double[][] chenfa = MathHUtils.chenfa( up2D,perspectiveTransformation);
		System.out.println("========");
		
		MathHUtils.print(chenfa);
		
		//perspectiveTransformation设定了取值大小，归一化了，
//		而chenfa2的第三个参数代表z·的值，如果不在-1到1之间，那么就不要去计算
		double[][] chenfa2 = MathHUtils.chenfa(chenfa, -1/z);
		MathHUtils.print(chenfa2);

		
		System.out.println("========");

		
		double[][] orthographicTransformation = Transform3D22D.OrthographicTransformation(100, 0.01, 0.5, -0.5, -0.5, 0.5);
		MathHUtils.print(orthographicTransformation);

		xyz1 = new double[]{-0.5,-0.5,-0.5,1};
		up2D = MathHUtils.up2D(xyz1);
		up2D = MathHUtils.zhuanzhi(up2D);
		orthographicTransformation = MathHUtils.zhuanzhi(orthographicTransformation);
		double[][] chenfa3 =MathHUtils.chenfa( up2D,orthographicTransformation);
		MathHUtils.print(chenfa3);

		
		System.out.println("========");

		double[][] screenSpace = Transform3D22D.ScreenSpace(520, 520);
		MathHUtils.print(screenSpace);

		
		xyz1 = new double[]{0.5,0.5,1,1};
		up2D = MathHUtils.up2D(xyz1);
		up2D = MathHUtils.zhuanzhi(up2D);
		screenSpace = MathHUtils.zhuanzhi(screenSpace);

		chenfa3 =MathHUtils.chenfa( up2D,screenSpace);
		MathHUtils.print(chenfa3);

		
		
	}



	
	
	
	
	

}
